
package ISOFT2.Pr03.Presentacion;
import ISOFT2.Pr03.Dominio.Cliente;

import java.awt.Color;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.JPasswordField;
import javax.swing.SwingConstants;




public class VentanaLogin extends JFrame {

	private JPanel contentPane;
	private JPanel panel;
	private JTextField tfUsuario;
	private JLabel lblUsuario;
	private JLabel lblContrasena;
	private JLabel lblAviso;
	private JButton btnEntrar;
	private JPasswordField pwdfContrasena;
	
	static VentanaLogin frame;
	static VentanaMenu menu;//=new VentanaMenu();

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {		
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					frame = new VentanaLogin();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public VentanaLogin() {
		setTitle("Acceso");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		{
			panel = new JPanel();
			panel.setBounds(5, 5, 424, 252);
			contentPane.add(panel);
			panel.setLayout(null);
			{
				tfUsuario = new JTextField();
				tfUsuario.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						//Activamos los de la contraseña
						lblContrasena.setEnabled(true);
						pwdfContrasena.setEnabled(true);
						//Pasamos el foco (el cursor) al campo de la contraseña
						pwdfContrasena.requestFocus();
					}
				});
				tfUsuario.setBounds(181, 75, 115, 20);
				panel.add(tfUsuario);
				tfUsuario.setColumns(10);
			}
			{
				lblUsuario = new JLabel("Usuario:");
				lblUsuario.setBounds(102, 75, 69, 20);
				panel.add(lblUsuario);
			}
			{
				lblContrasena = new JLabel("Contrase\u00F1a:");
				lblContrasena.setEnabled(false);
				lblContrasena.setBounds(102, 106, 69, 20);
				panel.add(lblContrasena);
			}
			{
				lblAviso = new JLabel("");
				lblAviso.setOpaque(true);
				lblAviso.setForeground(Color.BLACK);
				lblAviso.setHorizontalAlignment(SwingConstants.CENTER);
				lblAviso.setBounds(102, 137, 194, 20);
				panel.add(lblAviso);
			}
			{
				btnEntrar = new JButton("Continuar");
				btnEntrar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						menu=new VentanaMenu();
						VentanaLogin.frame.dispose();
						menu.setVisible(true);
			    		
					}
				});
				btnEntrar.setEnabled(false);
				btnEntrar.setBounds(137, 168, 115, 23);
				panel.add(btnEntrar);
			}
			{
				pwdfContrasena = new JPasswordField();
				pwdfContrasena.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						
						Cliente c=new Cliente();
						if(c.accesoSistema(String.valueOf(tfUsuario.getText()).toString(), String.valueOf(pwdfContrasena.getPassword()).toString())){
							lblAviso.setBackground(Color.GREEN);
							lblAviso.setText("Identificacion correcta.");
							lblAviso.setVisible(true);
							btnEntrar.setEnabled(true);
							lblContrasena.setEnabled(false);
							pwdfContrasena.setEnabled(false);
						}else{
							lblAviso.setBackground(Color.RED);
							lblAviso.setText("Usuario o contraseña erronea.");
							lblAviso.setVisible(true);
							btnEntrar.setEnabled(false);
							
						}
								
									
					}
				});
				pwdfContrasena.setEnabled(false);
				pwdfContrasena.setBounds(181, 106, 115, 20);
				panel.add(pwdfContrasena);
			}
		}
		
	}
}